package priv.pront.code.lanqiao.competition.course.date0403;

public class test1 {
    static int[] arr = {1, 2, 2,2, 9, 9, 9, 11, 15, 17, 19};
    static int target = 2;

    public static void main(String[] args) {
        System.out.println(method4());
    }

    private static int method1() {
        int left = 0;
        int right = arr.length - 1;
        while (left < right) {
            int mid = left + (right - left) / 2;
            if (arr[mid] >= target) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        return left;
    }

    private static int method2() {
        int left = 0;
        int right = arr.length - 1;
        while (left < right) {
            int mid = (left + right + 1) / 2;
            if (arr[mid] <= target) {
                left = mid;
            } else {
                right = mid - 1;
            }
        }
        return right;
    }

    //    查找第一个大于目标值的数
    private static int method3() {
        int left = 0;
        int right = arr.length - 1;
        while (left <= right) {
            int mid = left + (right - left) / 2;
            if (arr[mid] <= target) {
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }
        return left;
    }

//    查找第一个小于目标值的数
    private static int method4() {
        int left = 0;
        int right = arr.length - 1;
        while (left <= right) {
            int mid = left + (right - left) / 2;
            if (arr[mid] >= target) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return right;
    }

}
